package com.sfc.spiderweb.rest;

import com.sfc.spiderweb.entity.vo.Result;
import com.sfc.spiderweb.util.CommandUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@Api(tags = "liunx脚本")
@RestController
@RequestMapping(value = "/run")
@Slf4j
public class RunShellController {


    @ApiOperation(notes = "runShell", value = "runShell")
    @GetMapping("/runShell")
    public Result runShell() {
        String serverShell = "/ssd/start-server.sh";
        String controlShell = "/ssd/start-control.sh";
        try {
            log.info("run shell");
            CommandUtil.run(serverShell);
            CommandUtil.run(controlShell);
            log.info("run success");
            return Result.success();
        } catch (IOException e) {
            log.info("run file", e);
            return Result.fail(e);
        }
    }
}
